<?php

namespace App\Http\Requests;

use App\Http\Requests\Request;

class GoodsRequest extends Request
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'goods_name' => 'required',
            'cate_id' => 'required',
            'goods_img' => 'required',
            'goods_thumb' => 'required',
            'goods_num' => 'regex:/^[\d]+$/',
            'goods_price' => 'required|regex:/^[\d]+\.?[\d]*$/'
        ];
    }
    
    public function messages() {
        return [
            'goods_name.required' => '商品名称不能为空',
            'cate_id.required' => '必须要选择商品分类',
            'goods_img.required' => '请上传商品图片',
            'goods_thumb.required' => '请上传商品图片',
            'goods_num.regex' => '商品数量格式错误',
            'goods_price.required' => '商品价格不能为空',
            'goods_price.regex' => '商品价格格式错误'
        ];
       
    }
}
